﻿<CustomFilterView>
  <!-- The entity where the lookup field. Add other entity tags for other entities -->
  <entity name="account">
    <!-- Use the template to add filter view for other fields -->
    <targetField id="new_primarycontactid" viewentity="contact" viewname="Filtered Lookup View">
      <!-- this section defines the fields for which their values will be used to replace the correspondent fetchnote -->
      <dynamic>
        <!-- [operator] attribute value is from CRM advanced find. Leave empty if not specified -->
        <!-- this is an example to filter by a standard field in crm. only value will be used.  -->
        <field name="new_originatedcountry" fieldvaluetype="value" operator="contains" fetchnote="fnCountry"></field>
        <!-- this is an example to filter by a OptionSet field in crm. label of selected option will be used.  -->
        <field name="new_originatedcountryoptionset" fieldvaluetype="label" operator="contains" fetchnote="fnCountry"></field>
        <!-- this is an example to filter by a lookup field if out-of-box filtered lookups do not fit what you need. For example, the two lookups are random. -->
        <field name="new_originatedstateid" fieldvaluetype="name" operator="contains" fetchnote="fnCountry"></field>
      </dynamic>
      <!-- using advanced find to get the fetchXml -->
      <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
        <entity name="contact">
          <attribute name="fullname" />
          <attribute name="telephone1" />
          <attribute name="contactid" />
          <order attribute="fullname" descending="false" />
          <filter type="and">
            <condition attribute="new_country" operator="like" value="fnCountry" />
            <condition attribute="statuscode" operator="eq" value="1" />
          </filter>
        </entity>
      </fetch>
      <!-- this is the grid for the view -->
      <grid name="resultset" object="1" jump="contactid" select="1" icon="1" preview="1">
        <row name="result" id="contactid">
          <cell name="fullname" width="200" />
          <cell name="new_country" width="200" />
          <cell name="telephone1" width="200" />
        </row>
      </grid>
    </targetField>
  </entity>
</CustomFilterView>